'use strict';

module.exports = {
  async up (queryInterface, Sequelize) {
    const { INTEGER, DATE, STRING, ENUM, TEXT } = Sequelize;
    await queryInterface.createTable('report',{
      id: {type: INTEGER(20).UNSIGNED, primaryKey: true, autoIncrement: true},
      user_id: {type: INTEGER(20).UNSIGNED, allowNull: false, comment: '用户id',
        // 定义外键
        references: {
          model: 'user',  // 对应表名称
          key: 'id' // 对应表的主键
        },
        onUpdate: 'restrict', // 更新时操作
        onDelete: 'cascade' // 删除时操作
      },
      reported_id: { type: INTEGER(20).UNSIGNED, allowNull:false, comment: '被举报人id' },
      reported_type: { type: ENUM, 
        // 个人，群主
        values: ['user', 'group'], 
        allowNull: false, 
        comment: '举报类型' 
      },
      content: { type: TEXT, allowNull: true, defaultValue: '', comment: '举报内容' },
      category: { type:STRING(10), allowNull: true, defaultValue: '', comment: '举报分类' },
      status: { type: ENUM, values:['pending','refuse', 'agree'], allowNull: false, defaultValue: 'pending', comment: '举报状态' },
      created_at: DATE,
      updated_at: DATE
    });
  },

  async down (queryInterface, Sequelize) {
    await queryInterface.dropTable('report')
  }
};
